﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Pickle.Euler.Problems
{
	/// <summary>
	/// 
	/// </summary>
	public sealed class ProblemList
	{
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static IEnumerable<IEulerProblem> GetEulerProblems()
		{
			// I don't do much reflection, but this seems like a fragile mess of a way to
			// find types that are non-abstract classes that implement IEulerProblem
			Assembly Asm = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == "Pickle.Euler");

			foreach (Type T in Asm.GetTypes().Where(t => t.IsClass
				&& t.IsAbstract == false
				&& t.GetInterface(typeof(IEulerProblem).FullName) != null).OrderBy(t => t.FullName))
			{
				yield return (IEulerProblem)Asm.CreateInstance(T.FullName);
				//Console.WriteLine(T.Name);
			}
		}
	}
}
